/*
 * @Author: 来自火星的码农 15122322+heyzhi@user.noreply.gitee.com
 * @Date: 2025-09-30 18:12:46
 * @LastEditors: 来自火星的码农 15122322+heyzhi@user.noreply.gitee.com
 * @LastEditTime: 2025-10-03 14:29:23
 * @FilePath: /GateServer/src/rpc/VarifyGrpcClient.h
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */

 #pragma once

#include "../../build/message.pb.h"
#include"../util/global.h"
#include "../../build/message.grpc.pb.h"
#include "../util/singleton.h"
#include <atomic>
#include <condition_variable>
#include <cstddef>
#include <memory>
#include <mutex>
#include <queue>
#include <string>
class RpcConnectionPool;

class VarifyGrpcClient{

    public:
    VarifyGrpcClient();
    message::GetVarifyRsp GetVarifyCode(std::string);
    private:
   

    std::unique_ptr<message::GetVarifyService::Stub> m_stub;
    std::unique_ptr<RpcConnectionPool> m_pool;
};
class RpcConnectionPool{
    public:
    RpcConnectionPool(std::string ,std::string, size_t);
    ~RpcConnectionPool();
    std::unique_ptr<message::GetVarifyService::Stub>GetConnection();
    void ReturnConnection(std::unique_ptr<message::GetVarifyService::Stub>);
    void close();
    private:
    std::atomic<bool> m_stop={false};
    size_t m_pool_size;
    std::string m_host;
    std::string m_port;
    std::queue<std::unique_ptr<message::GetVarifyService::Stub>> m_connections;
    std::mutex m_mutex;
    std::condition_variable m_cond;


};
typedef Singleton<VarifyGrpcClient> VarifyGrpcClientMgr;
